<template>
  <el-tooltip effect="dark"  :content="!isEleFull ? '显示全屏' : '退出全屏'" placement="top">
    <el-button size="mini" circle icon="el-icon-full-screen" @click="click">
  </el-button>
  </el-tooltip>
</template>

<script>
import screenfull from 'screenfull'

export default {
  name: 'Screenfull',
  props: ['isEleFull'],
  data() {
    return {
    }
  },
  mounted() {
    this.init()
  },
  beforeDestroy() {
    this.destroy()
  },
  methods: {
    click() {
      if (!screenfull.isEnabled) {
        this.$message({ message: '你的浏览器不支持全屏', type: 'warning' })
        return false
      }
      screenfull.toggle()
      this.$emit('update:isEleFull', !this.isEleFull)
    },
    change() {
      // 退出全屏并且元素是全屏
      if(!screenfull.isFullscreen && this.isEleFull){
        this.$emit('update:isEleFull', !this.isEleFull)
      }
    },
    init() {
      if (screenfull.isEnabled) {
        screenfull.on('change', this.change)
      }
    },
    destroy() {
      if (screenfull.isEnabled) {
        screenfull.off('change', this.change)
      }
    }
  }
}
</script>

<style scoped>
.screenfull-svg {
  display: inline-block;
  cursor: pointer;
  fill: #5a5e66;;
  width: 20px;
  height: 20px;
  vertical-align: 10px;
}
</style>
